﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using BySoft.Server.Business;
using BySoft.Server.Common;

namespace SESS.Web.Site.UserControl.SuggestBox
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class GetLinkData : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.Clear();
            context.Response.Charset = "utf-8";
            context.Response.Buffer = true;
            context.Response.ContentEncoding = System.Text.Encoding.UTF8;
            context.Response.ContentType = "text/html";
            context.Response.Write(GetData(context.Request.QueryString["id"]));
            context.Response.Flush();
            //context.Response.Close();
            context.Response.End(); 
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

        private string GetData(string LinksTypeId)
        {
            DataTable dt = new DataTable();// FpLinks.SelectLink(LinksTypeId);
            string str = "";
            if (dt != null && dt.Rows.Count > 0)
            {
                int iLength = 0;
                int i = 0;
                foreach (DataRow item in dt.Rows)
                {
                    iLength = iLength + CommonMethod.GetString(item["LinkName"]).Length;
                    if (iLength>26)
                    {
                        iLength = CommonMethod.GetString(item["LinkName"]).Length;
                        str += "<br/>";
                    }
                    str += " <a href=\"HTTP://" + CommonMethod.GetString(item["LinkAddress"]) + "\" target='_blank' >" + CommonMethod.GetString(item["LinkName"]) + "</a>";
                    i++;
                }
            }
            return str.Trim();
        }
    }
}
